package com.mapapp.flutter_mapapp.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mapapp.flutter_mapapp.R;
import com.mapapp.flutter_mapapp.bean.ProcessBean;
import com.mapapp.flutter_mapapp.widget.CustomizedRoundProgressBar;

import java.util.List;

public class MapListStepAdapter extends BaseAdapter {
    private List<ProcessBean> mSteps;
    private Context mContext;

    public MapListStepAdapter(List<ProcessBean> steps , Context content){
        this.mSteps = steps;
        this.mContext = content;
    }

    @Override
    public int getCount() {
        return mSteps.size();
    }

    @Override
    public Object getItem(int position) {
        return mSteps.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = new ViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_map_step, null);
            holder.order = convertView.findViewById(R.id.tv_item_map_step_order);
            holder.percent = convertView.findViewById(R.id.tv_item_map_step_percent);
            holder.bar = convertView.findViewById(R.id.cpb_item_map_step_process);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String[] colors = mContext.getResources().getStringArray(R.array.stepcolor);
        ProcessBean bean = mSteps.get(position);
        holder.order.setText(bean.getProcessName());
        holder.percent.setText(bean.getProcessPercent()*100+"%");
        if(position < 5){
            holder.percent.setTextColor(Color.parseColor(colors[position]));
            holder.bar.setGradualColor(Color.parseColor(colors[position]));
        }else{
            holder.percent.setTextColor(Color.parseColor(colors[5]));
            holder.bar.setGradualColor(Color.parseColor(colors[5]));
        }
        holder.bar.setCurrentCount((float) bean.getProcessPercent()*100);
        return convertView;
    }

    class ViewHolder {
        private TextView order;
        private TextView percent;
        private CustomizedRoundProgressBar bar;
    }
}
